<!doctype html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<style type="text/css">
			.input {
				height: 100px;
				width: 500px;
				line-height: 1.5;
			}
		</style>
		<script type="text/javascript">
			var J = {
				id: function(idName) {
					return document.getElementById(idName);
				},
				tag: function(tagName) {
					return document.getElementsByTagName(tagName);
				}

			};


			onload = function() {
				var strbox = J.id("str"),
					regexbox = J.id("regex"),
					resbox = J.id("res");

				J.id("btn").onclick = function() {
					var txt = strbox.value,
						regex = regexbox.value;

					// alert(txt +"\n"+ regex);

					var r = new RegExp(regex, "g");

					var res = "", resTemp = null;

					while(resTemp = r.exec(txt)) {
						// index, length, 内容, 组
						res += "index: " + resTemp.index + "; length: " + resTemp[0].length + "; value: \"" + resTemp[0] + "\"";

						if (resTemp.length > 1) res += "; ";

						for (var i = 0, len = resTemp.length; i < len; i++) {
							res += "[" + i + "]: \"" + resTemp[i] + "\"; ";
						}

						res += "\n";
					}

					resbox.value = res;
				};
			}

		</script>
	</head>
	<body>
		字符串: <br />
		<textarea id="str" class="input"></textarea><br />
		正则表达式: <br />
		<textarea id="regex" class="input"></textarea><br />
		结果: <br />
		<textarea id="res" class="input"></textarea><br />
		<input type="button" value="处理" id="btn"/>
	</body>
</html>